'''
Created on Jun 9, 2012

@author: Timothy A. Mann
'''

import string

def readFile(filename):
    """
    Reads the entire text from a file into a string.
    
    @param filename path and name of a text file to read
    @return the string read from the given file
    """
    f = open(filename, 'r')
    text = ""
    for line in f:
        text = text + line
    return text

def extractSymbols(textStr, symbols=string.ascii_letters):
    """
    Extracts only the specified symbols from a string of text.
    
    @param textStr a string of text
    @param symbols a list of symbols to extract from the text
    @return a new string containing only the characters specified by symbols
    """
    textLetters = ""
    for c in textStr:
        if(c in symbols):
            textLetters = textLetters + c
    return textLetters

def extractLetters(textStr):
    """
    Extracts only the ASCII letters from a string of text.
    
    @param textStr a string of text
    @return a new string containing only ASCII letters
    """
    return extractSymbols(textStr)

def symbol_set(textStr):
    """
    Returns the set of symbols used in the text string.
    
    @param textStr a string of text
    @return the set of symbols used in the text string
    """
    symbols = set()
    for c in textStr:
        symbols.add(c)
    return symbols
